package com.google.code.server4j.component;

import java.util.concurrent.LinkedBlockingQueue;

public class BaseLifeCycle extends AbstractLifeCycle {

	private LinkedBlockingQueue<LifeCycle> queue = new LinkedBlockingQueue<LifeCycle>();
	
	@Override
	protected void executeInit()throws Exception {
		doInit();
		for(LifeCycle lc:queue) {
			lc.init();
		}
	}
	
	public void doInit()throws Exception {
		
	}

	@Override
	protected void executeStart()throws Exception {
		doStart();
		for(LifeCycle lc:queue) {
			lc.start();
		}
	}

	public void doStart()throws Exception {
		
	}
	
	@Override
	protected void executeStop()throws Exception {
		doStop();
		for(LifeCycle lc:queue) {
			lc.stop();
		}
	}
	
	public void doStop()throws Exception {
		
	}	
	
	public void addLifeCycleBean(LifeCycle lc) {
		if(!queue.contains(lc)) {
			queue.add(lc);
		}
	}
	
	public void removeLifeCycleBean(LifeCycle lc) {
		queue.remove(lc);
	}

}
